package cn.ms.doctor.Service;

import cn.ms.doctor.Entity.Drugs;
import cn.ms.doctor.Mapper.DrugsMapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Service
public class DrugsServiceImpl implements DrugsService {

    @Resource
    DrugsMapper drugsMapper;

    @Override
    public Map<String, Object> getDrugs(Map<String, Object> params) {
        Map<String, Object> data=new HashMap<>();
        Page<Object> objects = PageHelper.startPage((Integer) params.get("pageIndex"), (Integer) params.get("pageSize"));
        data.put("pageData",drugsMapper.getDrugs(params));
        data.put("pageIndex",objects.getPageNum());
        data.put("pageSize",objects.getPageSize());
        data.put("pageCount",objects.getPages());
        return data;
    }

    @Override
    public boolean updateDrugsByDrugsId(Drugs drugs) {
        return drugsMapper.updateDrugsByDrugsId(drugs);
    }

    @Override
    public boolean deleteDrugsByDrugsId(Drugs drugs) {
        return drugsMapper.deleteDrugsByDrugsId(drugs);
    }

    @Override
    public boolean addDrugs(Drugs drugs) {
        return drugsMapper.addDrugs(drugs);
    }
}
